package io.github.doc.action;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import io.github.doc.action.language.visitor.Visitor;

/**
 * 为当前元素生成注释
 *
 * @author ZH.Team
 * @version 1.0.0
 * @email "mailto:ZH.Team@zhxx.com"
 * @date 2025.01.27 18:50
 * @since y.y.y
 */
public class GenerateElementCommentAction extends AbstractAction {

    /**
     * Do action performed
     *
     * @param visitor visitor
     * @param e       e
     * @since y.y.y
     */
    @Override
    protected void doActionPerformed(Visitor visitor, AnActionEvent e) {
        Project project = e.getProject();
        PsiFile file = e.getData(CommonDataKeys.PSI_FILE);
        WriteCommandAction.runWriteCommandAction(project, () -> file.accept(visitor.generateElementVisitor(file, e)));
    }
}
